import cv2
import argparse
import numpy as np
from vino2 import Vino


# This function is used to choose argument,which is called init function
def parse_opt(local_path):
    parser = argparse.ArgumentParser()
    parser.add_argument('--model_path', type=str,
                        default=f"{local_path}\\weights\\best.xml",
                        help='model path')
    parser.add_argument('--weights_path', nargs='+', type=str,
                        default=f"{local_path}\\weights\\best.bin",
                        help='weights path or triton URL')
    parser.add_argument('--conf-thres', type=float, default=0.3, help='confidence threshold')
    parser.add_argument('--line-thickness', default=3, type=int, help='bounding box thickness (pixels)')
    parser.add_argument('--iou-thres', type=float, default=0.4, help='NMS IoU threshold')
    parser.add_argument('--classes', type=list, default=[], help='Classes')
    parser.add_argument('--img-size', type=int, default=640, help='img-size')
    parser.add_argument('--blob-acc', type=bool, default=True,
                        help='use blob model to acc detect and create blob model')
    parser.add_argument('--device', default='CPU', help='Intel npu device, i.e. 0 or 0,1,2,3 or cpu')
    parser.add_argument('--view-img', default=True, type=bool, help='view image or not')
    parser.add_argument('--name-process', default='Auto_identify', help='name to processs--cjh')
    opt = parser.parse_args()
    return opt


def detect(local_path):
    # 开始读取照片并进行识别
    model = Vino(**vars(parse_opt(local_path)))
    frame = cv2.imread(f"{local_path}/source_imgs/input_images/front.jpg", 1)
    frame_, det = model.run(frame)
    if det:
        # 单纯只是分离开，不做其他任何操作
        for xyxy, conf, cls in reversed(det):  # 识别物的类别像素坐标，置信度，物体类别号，进行分类
            print(xyxy,conf,cls)
    cv2.imshow("result", frame_)
    cv2.waitKey(0)


if __name__ == "__main__":
    detect("D:\eyedetector")
